package com.taptech.doufu.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.taptech.doufu.R;
import com.taptech.doufu.constant.Constant;
import com.taptech.doufu.ui.activity.base.DiaobaoBaseActivity;
import com.taptech.doufu.util.DiaobaoUtil;
import com.taptech.doufu.util.GlideUtil;
import com.taptech.doufu.util.UIUtil;

/**
 * Created by op0509 on 2016/5/24.
 */
public class NovelCreateContentAuthorActivity extends DiaobaoBaseActivity {
    private EditText etContent;
    private ImageView imgHead;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_novel_create_content_author_say);

        initUI();
        initData();
    }

    private void initUI() {
        etContent = (EditText) findViewById(R.id.et_novel_create_content_author_say);
        imgHead = (ImageView) findViewById(R.id.img_novel_create_content_author_say_head);
    }

    private void initData() {
        String str = getIntent().getStringExtra(NovelCreateContentTosActivity.SAY_CONTENT);
        String icon = getIntent().getStringExtra(Constant.IMAGE);
        if(DiaobaoUtil.getStringSizeNoSpace(str) > 0){
            etContent.setText(str);
            etContent.requestFocus();
        }
        if(!TextUtils.isEmpty(icon)){
            GlideUtil.displayCircleImage(imgHead, icon);
        }
    }

    public void back(View view){
        finish();
    }

    public void saveSay(View view){
        String content = etContent.getText().toString();
        if(DiaobaoUtil.getStringSizeNoSpace(content) > 500){
            UIUtil.toastMessage(this, "输入内容不能超过500字");
            return;
        }
//        if(DiaobaoUtil.getStringSizeNoSpace(content) <= 0){
//            UIUtil.toastMessage(this, "请输入想对大家说的话");
//            return;
//        }
        UIUtil.toastMessage(this, "作者有话说已保存");
        Intent intent = new Intent(this, NovelCreateContentTosActivity.class);
        intent.putExtra(NovelCreateContentTosActivity.SAY_CONTENT, content);
        setResult(NovelCreateContentTosActivity.RESULT_CODE_SAY_CONTENT, intent);
        finish();
    }
}
